// pages/orderInfo/orderInfo.js
const app = getApp();
const util = require("../../utils/util.js");
const api = require("../../utils/api.js");
Page({
    /**
     * 页面的初始数据
     */
    data: {
        orderINfo:"",
        ordersn:"",
        address: {
            name: "",
            mobile: "",
            address: ""
        },
        price:{
            goodsPrice:"88",
            fullCut:"20",
            redPackage:"10",
            postage:"8",
            goodsPrice:"38"
        },
        priceInfo: {
            //商品金额
            goodsPrice: 0,
            //满减金额
            cutPrice: 0,
            //红包金额
            redPacket: 0,
            //运费
            freight: 0,
            //是否限时实付款
            isShow:true,
            totalPrice:0

        },
        pageColor: app.pageColor.mainColor
    },
    
    onShow:function(){
        this.toOrderInfo(this.data.ordersn);
    },

    /**
     * 申请退款
     */
    refund:function(e){
        var position = e.currentTarget.dataset.position
        wx.navigateTo({
            url: '../customerService/customerService?goodInfo=' + JSON.stringify(this.data.orderINfo.orderDetail[position])
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var ordersn = options.ordersn;
        this.setData({
            ordersn: ordersn
        })

       
    },

    /**
     * 进入订单详情
     */
    toOrderInfo: function (ordersn){
        var that = this;
        let url = api.orderDetail();
        util.http(true,"GET", url, { order_sn: ordersn }, function (res) {
            //订单创建时间
            var date = new Date(res.created_at*1000);
            var created_at = util.formatAllTime(date) == "1970-01-01 08:00:00" ? false : util.formatAllTime(date);

            //订单付款时间
            var date = new Date(res.pay_at * 1000);
            var pay_at = util.formatAllTime(date) == "1970-01-01 08:00:00" ? false : util.formatAllTime(date);


            //订单发货时间
            var date = new Date(res.send_at * 1000);
            var send_at = util.formatAllTime(date) == "1970-01-01 08:00:00" ? false : util.formatAllTime(date);
            res.created_at = created_at
            res.pay_at = pay_at
            res.send_at = send_at

            var priceInfo = that.data.priceInfo;
            priceInfo.goodsPrice = res.good_price
            priceInfo.cutPrice = res.cut_price
            priceInfo.redPacket = res.red
            priceInfo.freight = res.freight
            priceInfo.totalPrice = res.total_price
            that.setData({
                orderINfo: res,
                address: res.address,
                priceInfo: priceInfo

            })
        })
    },
    onReady: function () {
        util.setNavigationBarTitle("订单详情");
    },
})